package com.zt.springcloud.factory;


import com.zt.springcloud.RemoteUserService;
import com.zt.springcloud.entity.Address;
import com.zt.springcloud.entity.Role;
import com.zt.springcloud.entity.User;
import feign.hystrix.FallbackFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Set;

/**
 * 用户服务降级处理
 *
 * @author ruoyi
 */
@Component
public class RemoteUserFallbackFactory implements FallbackFactory<RemoteUserService>
{
    private static final Logger log = LoggerFactory.getLogger(RemoteUserFallbackFactory.class);

    @Override
    public RemoteUserService create(Throwable throwable)
    {
        log.error("用户服务调用失败:{}", throwable.getMessage());
        return new RemoteUserService()
        {
            @Override
            public Set<Role> getRolesInfo(Long id) {
                return null;
            }

            @Override
            public Integer addUserAddress(Address address) {
                return 0;
            }

            @Override
            public List<Address> getAddressInfo(Long userid) {
                return null;
            }

            @Override
            public Integer updateAddressInfo(Address address) {
                return 0;
            }

            @Override
            public User getUserInfo(String username)
            {
                log.info("获取用户失败");
                return new User();
            }
        };
    }
}
